const app = getApp()
import {
	request
} from '../../utils/request.js'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		list: [],
		radio: '1',
		ckIndex: -1
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {

	},
	defAddress(e) {
		let id = e.currentTarget.dataset.id;
		let ckIndex = e.currentTarget.dataset.index;
		this.setData({
			ckIndex
		})
		request({
			url: 'defAddress',
			token: wx.getStorageSync('token'),
			method: 'POST',
			data: {
				id: id
			}
		}).then(res => {
			this.addressList()
		})
	},
	getAddressById(e) {
		let id = e.currentTarget.dataset.id;
		wx.navigateTo({
			url: `/pages/adressEdit/adressEdit?id=${id}`
		})
	},
	deleteAddress(e) {
		let id = e.currentTarget.dataset.id;
		wx.showModal({
			title: '提示',
			content: '确认要删除该该收货地址吗？',
			success: res => {
				if (res.confirm) {
					request({
						url: 'delAddressOne',
						token: wx.getStorageSync('token'),
						method: 'POST',
						data: {
							id: id
						}
					}).then(res => {
						this.addressList()
					})
				} else {
					console.log('点击取消回调')
				}
			}
		})
	},
	addAddress() {
		wx.navigateTo({
			url: `/pages/adressEdit/adressEdit`
		})
	},
	onChange(event) {
		this.setData({
			radio: !this.data.radio
		});
	},
	addressList() {
		request({
			url: 'addressList',
			token: wx.getStorageSync('token'),
			method: 'POST',
			data: {
				// type:1
			}
		}).then(res => {
			this.setData({
				list: res.data.data
			})
		})
	},
	onShow: function() {
		this.addressList()
	},



	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */


	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
